package services

import (
	"gitee.com/cjf8134/bbs_serve/internal/pkg/requests"
	"gitee.com/cjf8134/bbs_serve/internal/pkg/responses"
)

// CategoryList 分类列表
func (s *DefaultService) CategoryList(req *requests.CategoryList) (cateGoryList []*responses.CategoryList, err error) {
	list, err := s.Repository.CategoryList(req)
	if err != nil || len(list) == 0 {
		return
	}
	for _, value := range list {
		category := &responses.CategoryList{
			ID:        value.ID,
			Name:      value.Name,
			PID:       value.PID,
			TotalNum:  value.TotalNum,
			CreatedAt: value.CreatedAt.Format("2006-01-02 15:04:05"),
			UpdatedAt: value.UpdatedAt.Format("2006-01-02 15:04:05"),
		}
		cateGoryList = append(cateGoryList, category)
	}
	return
}
